package com.xbongbong.saas.script.tempenum;

import com.xbongbong.i18n.util.I18nMessageUtil;
import com.xbongbong.paas.enums.DateTimeEnum;
import com.xbongbong.paas.enums.DefaultTypeEnum;
import com.xbongbong.paas.enums.DefaultValueEnum;
import com.xbongbong.paas.field.DefaultAttrPoJo;
import com.xbongbong.paas.field.FieldAttrEntity;
import com.xbongbong.paas.field.LinkDetailPojo;
import com.xbongbong.paas.help.FormDataFormExplainHelper;
import com.xbongbong.pro.enums.SaasMarkEnum;
import com.xbongbong.saas.constant.StringConstant;
import com.xbongbong.saas.enums.RedundantTemplateTypeEnum;
import com.xbongbong.saas.enums.RedundantTemplateTypeEnum;
import com.xbongbong.saas.enums.XbbRefTypeEnum;
import com.xbongbong.saas.enums.business.CostAdjustEnum;
import com.xbongbong.saas.enums.business.OutstockEnum;
import com.xbongbong.saas.script.help.InitExplainsHelper;
import com.xbongbong.sys.enums.RoleEnum;
import lombok.Getter;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @author WuHB
 * @date 2021/11/18 09:11
 */
@Getter
public enum TempCostAdjustEnum {


    // 基础信息
    BASE_INFO(CostAdjustEnum.BASE_INFO),
    // 调整单编号
    ADJUST_NO(CostAdjustEnum.ADJUST_NO),
    // 调整单日期
    ADJUST_TIME(CostAdjustEnum.ADJUST_TIME),
    // 成本调整仓库
    WAREHOUSE_ID(CostAdjustEnum.WAREHOUSE_ID),
    // 产品信息
    PRODUCT_INFO(CostAdjustEnum.PRODUCT_INFO),
    // 关联产品
    PRODUCT(CostAdjustEnum.PRODUCT),
    // 扩展信息
    EXTEND_INFO(CostAdjustEnum.EXTEND_INFO),
    //负责人
    OWNER_ID(CostAdjustEnum.OWNER_ID),
    //备注
    MEMO(CostAdjustEnum.MEMO),
    // 系统信息
    SYSTEM_INFO(CostAdjustEnum.SYSTEM_INFO),
    // 创建人
    CREATOR_ID(CostAdjustEnum.CREATOR_ID),
    // 创建时间
    ADD_TIME(CostAdjustEnum.ADD_TIME),
    // 修改时间
    UPDATE_TIME(CostAdjustEnum.UPDATE_TIME),
    // 调整单仓库关联显示值
    WAREHOUSE_ID_LINKED_TEXT(CostAdjustEnum.WAREHOUSE_ID_LINKED_TEXT),
    ;

    /**
     * 调整单枚举
     */
    private final CostAdjustEnum anEnum;


    TempCostAdjustEnum(CostAdjustEnum anEnum) {
        this.anEnum = anEnum;
    }

    public static List<TempCostAdjustEnum> getAllEnum() {
        List<TempCostAdjustEnum> list = new ArrayList<>();
        Collections.addAll(list, values());
        return list;
    }

    /**
     * 初始化调整单编号
     *
     * @param fieldAttrEntity 表单字段属性实体类
     */
    public static void initAdjustNo(FieldAttrEntity fieldAttrEntity) {
        LinkDetailPojo linkDetailPojo = new LinkDetailPojo();
        linkDetailPojo.setBusinessType(XbbRefTypeEnum.COST_ADJUST.getCode());
        linkDetailPojo.setSubBuisenssType(XbbRefTypeEnum.COST_ADJUST.getCode());
        linkDetailPojo.setSaasMark(SaasMarkEnum.SAAS.getCode());
        linkDetailPojo.setAttr(ADJUST_NO.getAnEnum().getAttr());
        fieldAttrEntity.setLinkDetail(linkDetailPojo);
        fieldAttrEntity.setNoRepeat(1);
        fieldAttrEntity.setSerialNumber(InitExplainsHelper.setSerialNumber(SerialNumberEnum.ADJUST_NO));
        fieldAttrEntity.setIsForbidden(0);
        fieldAttrEntity.setStrictController(0);
        fieldAttrEntity.setShowEditable(1);
    }

    /**
     * 初始化调整单日期
     *
     * @param fieldAttrEntity 表单字段属性实体类
     */
    public static void initAdjustTime(FieldAttrEntity fieldAttrEntity) {
        DefaultAttrPoJo defaultAttrPoJo = new DefaultAttrPoJo();
        defaultAttrPoJo.setDefaultType("today");
        fieldAttrEntity.setDefaultAttr(defaultAttrPoJo);
        fieldAttrEntity.setDateType(DateTimeEnum.TIME.getType());
        fieldAttrEntity.setIsForbidden(0);
        fieldAttrEntity.setRequired(1);
    }

    /**
     * 初始化出库仓库
     * 将关联显示的字段设置到出库仓库字段中
     *
     * @param fieldAttrEntity 字段解释实体--saas专用
     */
    public static void initWarehouseId(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setLinkedText(CostAdjustEnum.WAREHOUSE_ID_LINKED_TEXT.getAttr());
        fieldAttrEntity.setLinkedType(XbbRefTypeEnum.WAREHOUSE.getCode());
        fieldAttrEntity.setIsForbidden(0);
        fieldAttrEntity.setRequired(0);
        fieldAttrEntity.setEditable(1);
    }

    /**
     * 初始化产品
     *
     * @param fieldAttrEntity 表单字段属性实体类
     */
    public static void initProducts(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setIsForbidden(0);
    }

    /**
     * 初始化负责人
     *
     * @param fieldAttrEntity 表单字段属性实体类
     */
    public static void initOwnerId(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setMultiple(0);
        fieldAttrEntity.setRequired(1);
        //可新增权限：默认【超级管理员、销售主管、创建人、负责人、负责人主管】可新增负责人，支持自定义；
        fieldAttrEntity.setShowEditable(0);
        fieldAttrEntity.setAdd(1);
        fieldAttrEntity.setAddAdvanceEnable(1);
        fieldAttrEntity.setShowAdd(1);
        //可删除权限：默认【超级管理员、销售主管】可删除负责人，支持自定义；
        fieldAttrEntity.setRemove(1);
        fieldAttrEntity.setRemoveAdvanceEnable(1);
        fieldAttrEntity.setShowRemove(1);
        fieldAttrEntity.setIsForbidden(0);
        fieldAttrEntity.setEditable(1);
        fieldAttrEntity.setUnableEditMemo(null);
        fieldAttrEntity.setRequired(1);
        fieldAttrEntity.setAddRule(FormDataFormExplainHelper.getDefaultRule(RoleEnum.TREASURER));
        fieldAttrEntity.setRemoveRule(FormDataFormExplainHelper.getDefaultRule(RoleEnum.TREASURER));
        // 设置默认值
        DefaultAttrPoJo defaultAttrPoJo = new DefaultAttrPoJo();
        defaultAttrPoJo.setDefaultType(DefaultTypeEnum.DYNAMIC.getAlias());
        defaultAttrPoJo.setDefaultValue(DefaultValueEnum.LOGIN_USER.getValue());
        fieldAttrEntity.setDefaultAttr(defaultAttrPoJo);
    }

    /**
     * 初始化创建人
     *
     * @param fieldAttrEntity 表单字段属性实体类
     */
    public static void initCreatorId(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setEditable(0);
        fieldAttrEntity.setUnableEditMemo(I18nMessageUtil.getMessage(StringConstant.AUTO_GEN_FIELD));
    }

    /**
     * 初始化添加时间
     *
     * @param fieldAttrEntity 表单字段属性实体类
     */
    public static void initAddTime(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setEditable(0);
        fieldAttrEntity.setUnableEditMemo(I18nMessageUtil.getMessage(StringConstant.AUTO_GEN_FIELD));
    }

    /**
     * 初始化修改时间
     *
     * @param fieldAttrEntity 表单字段属性实体类
     */
    public static void initUpdateTime(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setEditable(0);
        fieldAttrEntity.setUnableEditMemo(I18nMessageUtil.getMessage(StringConstant.AUTO_GEN_FIELD));
    }
}
